﻿using System;
using System.Globalization;
using System.IO;

namespace ObjectMapper.Benchmark
{
    public class AdventureWorksResult : ExecutionResult
    {
        public AdventureWorksResult(Type sourceType, Type targetType, int recordCount)
            : base(recordCount)
        {
            SourceType = sourceType;
            TargetType = targetType;
        }

        public Type SourceType { get; private set; }

        public Type TargetType { get; private set; }

        public new static void WriteConsoleHeader()
        {
            Console.Write("Name".PadRight(25, ' ') + " ");
            Console.Write("Properties ");
            ExecutionResult.WriteConsoleHeader();
        }

        public override void WriteConsoleRow()
        {
            var typeName = SourceType.Name;
            if (typeName.Length > 25)
            {
                typeName = typeName.Substring(0, 23) + "~1";
            }
            Console.Write(typeName.PadRight(25, ' ') + " ");
            Console.Write(SourceType.GetProperties().Length.ToString(CultureInfo.InvariantCulture).PadLeft(10, ' ') + " ");
            base.WriteConsoleRow();
        }

        public new static void WriteCsvHeader(StreamWriter writer)
        {
            writer.Write("Name,Properties,");
            ExecutionResult.WriteCsvHeader(writer);
        }

        public override void WriteCsvRow(StreamWriter writer)
        {
            writer.Write(SourceType.Name);
            writer.Write(",");
            writer.Write(SourceType.GetProperties().Length.ToString(CultureInfo.InvariantCulture));
            writer.Write(",");
            base.WriteCsvRow(writer);
        }
    }
}
